/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.google.code.netbuilder.util;

import com.google.code.netbuilder.dal.entities.ManagedObject;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Андрей
 */
public class ManagedObjectDataModel<T extends ManagedObject> extends ListDataModel<T> implements SelectableDataModel<T> {
    
    public ManagedObjectDataModel(List<T> mo) {
        super(mo);
    }
   
    @Override
    public Object getRowKey(ManagedObject mo) {
        return String.valueOf(mo.getId());
    }

    @Override
    public T getRowData(String rowKey) {
        List<T> mos = (List<T>) getWrappedData();
        
        for(T mo : mos)
        {
            if(String.valueOf(mo.getId()).equals(rowKey))
            {
                return mo;
            }
        }
        return null;
        
    }
    
}
